
INS_DIR	:= ../../bin/

CFLAGS 		+= -Wall -fPIC -Werror -g -w -DDEBUG=1 -fmessage-length=0 -O2
CFLAGS		+= -I../include

CXXFLAGS	= $(CFLAGS)

LDFLAGS		+= -Wl,--as-needed
LDFLAGS		+= -L$(INS_DIR) -lmincrypt

ifneq ($(strip $(TOOLS_BUILD_SHARED)),)
LDFLAGS		+= -Wl,-rpath=.:./bin
endif

SRCS := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(SRCS))

TARGET	:= mkbootimg exbootimg

all:$(TARGET)

mkbootimg:mkbootimg.o
	$(CC) -o $@ $^ $(LDFLAGS)
	$(STRIP) $@
	@cp -vf $@ $(INS_DIR)

exbootimg:exbootimg.o
	$(CC) -o $@ $^ $(LDFLAGS)
	$(STRIP) $@
	@cp -vf $@ $(INS_DIR)

%.o:%.c
	$(CC) $(CFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o $@ $<

%.o:%.cpp
	$(CXX) $(CXXFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o $@ $<

sinclude $(SRCS:.c=.d)

install:
	test -d $(INS_DIR) || install -m 755 -d $(LIBDIR)
	install -m 755 $(TARGET) $(INS_DIR)

clean:
	-rm -rf $(OBJS) *.d $(TARGET)

.PHONY: all clean install

